﻿/*
    * Test model: RedMi note 9 4G
    * Auth:机器喵
    * QQ:1433668136
*/
function getRgbSum(img, x, y) {
    let color = images.pixel(img, x, y);
    let r = colors.red(color);
    let g = colors.green(color);
    let b = colors.blue(color);
    let sum = r + g + b;
    return sum;
}
function sloder(x1, y1, x2, y2, shadowLen) {
    var img = captureScreen();
    var dt = "" //the distance
    var shadowBin = ""
    var judge = 0;
    for (let k = 0; k < shadowLen; k++) {
        shadowBin = shadowBin + 0 + "";
    }
    var length
    var s = new Array(4);
    s[0] = "1" + shadowBin + "1";
    s[1] = "1" + shadowBin + "01";
    s[2] = "1" + shadowBin + "001";
    s[4] = "1" + shadowBin + "0001";
    for (let j = y1; j <= y2; j++) {
        dt = "";
        for (let i = x1; i <= x2; i++) {
            let result = getRgbSum(img, i, j);
            if (result < 384) {
                result = 0;
                dt = dt + result + "";
            } else {
                result = 1;
                dt = dt + result + "";
            }
        }
        for (let k in s) {
            length = dt.indexOf(s[k], x2 / 2);
            if (length != -1) {
                judge++;
                break;
            }
        }

        if (judge == 6) {
            return length+x1;
        }
    }
}
requestScreenCapture();
console.show();
console.setPosition(202,1400)
// x1, y1, x2, y2  the bounds of sloder
var shadowLen = 127 // the length of shadow sloder Be sure to fill it in correctly
let point_x = sloder(48,387,1028,946,shadowLen);
log("point_x:"+point_x);
swipe(156,1044,point_x,1044,600);